package com.cjl.blueBridgeCup.warmUp;


import java.awt.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class WarmUp_1014 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 1.三带一
        /*int num = sc.nextInt();
        for (int i = 0; i < num; i++) {
            String str = sc.next();
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            if (chars[0] == chars[1] && chars[1] == chars[2] && chars[2] != chars[3]) {
                System.out.println("Yes");
            } else if (chars[1] == chars[2] && chars[2] == chars[3] && chars[0] != chars[1]) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }*/

        // 2.树与树
        int n = sc.nextInt();
        int p = sc.nextInt();
        String a = "";
        for(int i = 0 ; i < p ; i++){
            a = sc.next();
            int val = 1;
            for(int j = 0 ; j < a.length() ; j++){
                if(a.charAt(j) == 'R'){
                    val*=2;
                }else if(a.charAt(j) == 'L'){
                    val = val*2-1;
                }
            }
            System.out.println(val);
        }

        // 3.分组

        sc.close();
    }
}
